﻿// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "UiCustom/InclineImage"
{
	Properties
	{
		_MainTex("Main Tex", 2D) = "white" {}
		_Incline("Incline", Range(0, .99)) = 0.1	//倾斜度
	}

	SubShader
		{
			Tags{ "Queue" = "Geometry" }
			Pass
			{
				Tags{ "LightMode" = "ForwardBase" }
				ZWrite Off
				Blend SrcAlpha OneMinusSrcAlpha

				CGPROGRAM
				#pragma vertex vert  
				#pragma fragment frag
				#include "UnityCG.cginc"
				#define PI 3.14159265358979  

				sampler2D _MainTex;
				float _Incline;
				struct a2v
				{
					float4 vertex : POSITION;
					float3 texcoord : TEXCOORD0;
				};

				struct v2f
				{
					float4 pos : SV_POSITION;
					float2 uv : TEXCOORD0;
				};

				v2f vert(a2v v)
				{
					v2f o;
					o.pos = UnityObjectToClipPos(v.vertex);
					o.uv = v.texcoord;
					return o;
				}

				fixed4 frag(v2f i) : SV_Target
				{
					if (i.uv.x < i.uv.y * _Incline || i.uv.x > 1 - (1 - i.uv.y) * _Incline)
						return fixed4(1, 1, 1, 0);
					//i.uv.x = i.uv.x * (1 - _Incline) + i.uv.y * _Incline;
					i.uv.x = (i.uv.x - i.uv.y * _Incline) / (1 - _Incline); //这其实就是上式的逆变换
					return tex2D(_MainTex, i.uv);
				}
				ENDCG
			}
		}
		FallBack "Specular"
}